﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using DelonixRegiaHotel.Classes;
using DelonixRegiaHotel.DBManager;
using System.Collections;


namespace DelonixRegiaHotel
{
    public partial class DeleteStaff : Form
    {
        string staffid;

        public DeleteStaff()
        {
            InitializeComponent();

            foreach (Staff s in StaffAndDutyDBManager.GetAllStaffInfo())
            {
                comboStaffSearch.Items.Add(s.FirstName + " " + s.LastName + " (Nric: " + s.Nric + ")");
            }
        }

        private void comboStaffSearch_SelectedIndexChanged(object sender, EventArgs e)
        {
            ArrayList staff = StaffAndDutyDBManager.GetAllStaffInfo();
                foreach (Staff s in staff)
                {
                    if ( comboStaffSearch.SelectedItem.ToString().Contains(s.FirstName) && comboStaffSearch.SelectedItem.ToString().Contains(s.LastName) && comboStaffSearch.SelectedItem.ToString().Contains(s.Nric))
                    {
                        labelStaffId.Text = s.StaffID;
                        labelFn.Text = s.FirstName;
                        labelLn.Text = s.LastName;
                        labelNric.Text = s.Nric;
                        tbxDelAdd.Text = s.HomeAddress;
                        labelPostalCode.Text = Convert.ToString(s.PostalCode);
                        labelDob.Text = Convert.ToString(s.Dob);
                        labelContactNo.Text = Convert.ToString(s.ContactNo);
                        labelEmail.Text = s.Email;
                        labelBankAcc.Text = Convert.ToString(s.BankAccountNo);
                        labelPwd.Text = s.Password;
                        labelAccessLvl.Text = Convert.ToString(s.AccessLevel);
                        labelDutyTypeId.Text = Convert.ToString(s.DutyTypeID);
                        labelShiftType.Text = s.ShiftType;
                        labelHourlyRate.Text = Convert.ToString(s.HourlyRate);
                        labelWorkHours.Text = Convert.ToString(s.WorkHours);
                        tbxShiftDays.Text = s.ShiftDay;

                    }
                }

        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnDelete_Click(object sender, EventArgs e)
        {

            if (StaffAndDutyDBManager.DeleteStaffByID(labelStaffId.Text) == 1)
            {
                MessageBox.Show("Staff successfully deleted");
            }

            else
            {
                MessageBox.Show("Delete unsuccessful");
            }
            this.Hide();
        }

    }
}
